package javaCode.chapter05.本章作业;

public class Homework04 {

    public static void main(String[] args) {

        //冒泡排序
        int[] arr = {33, 22, 55, 88, 2};
        int len = arr.length - 1;
        int temp = 0; //赋值交换

        for (int i = 0; i < len; i++) { //外层循环

            for (int j = 0; j < len - i; j++) { //每轮的比较次数
                //如果是从小到大，条件是 arr[j] > arr[j + 1]
                //如果是从大到笑，条件是 arr[j] < arr[j + 1]
                if (arr[j] > arr[j + 1]) { //前面的数大 就交换
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        System.out.println("===arr冒泡后的情况===");
        for (int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }


    }
}
